﻿using System;
using System.Collections.Specialized;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// SessionHelper 的摘要说明
/// </summary>
public class SessionHelper
{
    private static string userDetails = "userDetails"; //user details state
    public static DataRow UserDetails
    {
        get
        {
            return (DataRow)HttpContext.Current.Session[userDetails];
        }
        set
        {
            HttpContext.Current.Session[userDetails] = value;
        }
    }


    //Check is any session alive
    public static bool IsAnySessionAlive()
    {
        foreach (string strKey in HttpContext.Current.Session.Keys)
        {
            if (HttpContext.Current.Session[strKey] != "")
                return true;
        }
        return false;
    }

    public static void Remove(string str)
    {
        HttpContext.Current.Session.Remove(str);
    }

    public static bool ChkValidVisit()
    {
        if (UserDetails == null)
        {
            ((Page)HttpContext.Current.Handler).RegisterClientScriptBlock("alert", "<script>alert('您还未登录，请先登录');location.href='index.aspx?ReturnUrl=" + HttpContext.Current.Server.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri) + "'</script>");
            return false;
        }
        return true;
    }



}

